package com.powernode.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.ProdComm;
import com.powernode.service.ProdCommService;
import com.powernode.vo.ProdCommView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "评论接口管理")
@RestController
@RequestMapping("/prod/prodComm")
public class ProdCommController {
    @Autowired
    private ProdCommService prodCommService;

    @ApiOperation("多条件分页查询商品评论列表")
    @GetMapping("/page")
    @PreAuthorize("hasAnyAuthority('prod:prodComm:page')")
    public ResponseEntity<Page<ProdComm>> loadProdComment(Page<ProdComm> page, ProdComm prodComm) {
        prodCommService.selectProdCommPage(page, prodComm);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("根据评论标识查询评论详情")
    @GetMapping("/{prodCommId}")
    @PreAuthorize("hasAnyAuthority('prod:prodComm:info')")
    public ResponseEntity<ProdComm> loadProdComm(@PathVariable Long prodCommId) {
        ProdComm prodComm = prodCommService.getById(prodCommId);
        return ResponseEntity.ok(prodComm);
    }

    @ApiOperation("回复评论并审核评论")
    @PutMapping
    @PreAuthorize("hasAnyAuthority('prod:prodComm:update')")
    public ResponseEntity<Void> updateProdComm(@RequestBody ProdComm prodComm) {
        prodCommService.updateById(prodComm);
        return ResponseEntity.ok().build();
    }

    @ApiOperation("查询评论总览")
    @GetMapping("/prodComm/prodCommData")
    public ResponseEntity<ProdCommView> loadProdCommView(@RequestParam Long prodId) {
        ProdCommView prodCommView = prodCommService.selectProdCommView(prodId);
        return ResponseEntity.ok(prodCommView);
    }

    @ApiOperation("分页查询评论")
    @GetMapping("/prodComm/prodCommPageByProd")
    public ResponseEntity<Page<ProdComm>> loadCommPage(Page<ProdComm> page, ProdComm prodComm) {
        prodCommService.selectCommPage(page, prodComm);
        return ResponseEntity.ok(page);
    }
}
